﻿Public Class songs
    Inherits System.Web.UI.Page

    Protected PageSize As Integer = 10
    Protected TotalRecords As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim q As String = Request.QueryString("q")
        Dim p As Integer
        Integer.TryParse(Request.QueryString("p"), p)
        Dim filter As FMW.FMWBO.SongFilterType

        If Not String.IsNullOrEmpty(Request.QueryString("f")) Then
            filter = [Enum].Parse(GetType(FMW.FMWBO.SongFilterType), Request.QueryString("f"))
        End If

        Dim lst As List(Of FMW.Song)

        If Not String.IsNullOrEmpty(q) Then
            lst = FMW.FMWBO.ListSongs(q, p, PageSize, TotalRecords, filter)

            ltlHeader.Text = String.Format("Search Results (Showing {0} - {1} of {2})", (PageSize * p) + 1, (PageSize * p) + lst.Count, TotalRecords)
        Else
            ltlHeader.Text = "Recent Updated Songs"
            lst = FMW.FMWBO.GetTop5LastUpdatedSongs()
        End If




        fillGrid(lst)
    End Sub

    Private Sub fillGrid(ByVal o As List(Of FMW.Song))
        If o IsNot Nothing AndAlso o.Count > 0 Then
            rptSongs.DataSource = o
            rptSongs.DataBind()
        Else
            ltl1.Text = "Sorry!!! No Record found."
        End If
    End Sub

End Class